import request from '@/utils/request'

// 获取角色列表
export function getRoleList() {
  return request({
    url: '/system/role/list',
    method: 'get'
  })
}

// 根据ID获取角色信息
export function getRoleById(roleId) {
  return request({
    url: `/system/role/${roleId}`,
    method: 'get'
  })
}

// 新增角色
export function addRole(data) {
  return request({
    url: '/system/role/add',
    method: 'post',
    data
  })
}

// 更新角色
export function updateRole(data) {
  return request({
    url: '/system/role/update',
    method: 'put',
    data
  })
}

// 删除角色
export function deleteRole(roleId) {
  return request({
    url: `/system/role/delete/${roleId}`,
    method: 'delete'
  })
}

// 分配权限
export function assignPermissions(roleId, permissionIds) {
  return request({
    url: `/system/role/assignPermissions/${roleId}`,
    method: 'post',
    data: permissionIds
  })
}

// 获取用户角色
export function getRolesByUserId(userId) {
  return request({
    url: `/system/role/user/${userId}`,
    method: 'get'
  })
}
